import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/ui/widget/custom_button.dart';

class NewPasword extends StatefulWidget {

  NewPasword({Key key}) : super(key: key);

  @override
  _NewPasword createState() {
    return _NewPasword();
  }
}

class _NewPasword extends State<NewPasword> {

  TextEditingController _unameController = new TextEditingController();
  TextEditingController _pwdController = new TextEditingController();
  GlobalKey _formKey= new GlobalKey<FormState>();
  var list = ['+86', '+852', '+853'];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(title:  Text('修改密码'),),body: Form(
      key: _formKey, //设置globalKey，用于后面获取FormState
      autovalidate: true, //开启自动校验
      child: Center(
        child: Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 50),
              width: 280,
              child: TextFormField(
                  autofocus: true,
                  controller: _unameController,
                  decoration: InputDecoration(
//                    labelText: "手机号码",
                    hintText: "输入新密码",
                  ),
                  // 校验用户名
                  validator: (v) {
                    return v
                        .trim()
                        .length > 0 ? null : "密码不能为空";
                  }

              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
              width: 280,
              child: TextFormField(
                  controller: _pwdController,
                  decoration: InputDecoration(
                    labelText: "确认新密码",
                  ),
                  obscureText: true,
                  //校验密码
                  validator: (v) {
                    return v
                        .trim()
                        .length > 5 ? null : "密码不能少于6位";
                  }
              ),
            ),

            /// 点击绑定
            GestureDetector(onTap: (){
              print('点击登录了');
              //在这里不能通过此方式获取FormState，context不对
//              print(Form.of(context));
//
//              // 通过_formKey.currentState 获取FormState后，
//              // 调用validate()方法校验用户名密码是否合法，校验
//              // 通过后再提交数据。
              if((_formKey.currentState as FormState).validate()){
                print('FormState${FormState}');
              }else{
                print('没有拿到值');
              }
//                //验证通过提交数据
            },child:  CustomButton(
                margin: EdgeInsets.only(top: 20),
                padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                widgt: 250.0,
                title: '确认保存',
                fontSize: AppFontSize.Size18,
                fontColor: Colors.white,
                radius: 30.0,
                borderColor: Colors.transparent,
                gradient:AppColor.gradientColorHigh),),

          ],
        ),
      ),
    ),
    );
  }
}

